iOS provides a CoreGraphics framework that came from iOS version 2.0. CoreGraphics provides CGGeometry for our iOS application development that helps in positioning views or creating drawing by programmatically. CGGeometry is a collection of structures, constants and functions. CGGeometry provides many more methods like comparing values, checking memberships, and so on. Some of the methods and data types are described below.
CGGeometry have some data types that help to create shapes or designs, these are as follows:
CGPoint: it is a basic type for all floating-point values. It takes two
CGFloat (float) values for width and height.
Syntax: struct CGPoint {CGFloat x, CGFloat y};
Field x is the x-coordinate of the point and field y is the y-coordinate of the
point.
CGSize: it is a structure that contains the width and height values.
Syntax: struct CGSize {CGFloat width, CGFloat height};
CGRect: it is a structure that contains the location and dimensions of a rectangle. It takes both CGPoint (origin) and CGSize (size) in its parameter. When we use origin and size fields it defines the position and the size of a rectangle.
Syntax: struct CGRect {CGPoint origin, CGSize size};
CGVector: it is a structure that contains the two dimensional vector.
Syntax: struct CGVector {CGFloat x, CGFloat y };
CGGeometry provides two methods to get height and width according to the specified rectangle, these are:
CGRectGetHeight: it takes CGRect reference and returns the height of the rectangle.
Syntax: CGFloat CGRectGetHeight (CGRect rect);
CGRectGetWidth: it also takes CGRect reference and returns the width of the rectangle.
Syntax: CGFloat CGRectGetWidth (CGRect rect);
CGGeometry provides some methods to get minimum, center and largest values according to the specified rectangle, these are:
CGRectGetMinX: it takes CGRect reference and returns the minimum (smallest) value of x-coordinate of the specified rectangle.
Syntax: CGFloat CGRectGetMinX(CGRect rect);
CGRectGetMinY: it takes CGRect reference and returns the minimum (smallest) value of y-coordinate of the specified rectangle.
Syntax: CGFloat CGRectGetMinY(CGRect rect);
CGRectGetMidX: it takes CGRect reference and returns the center value of the x-coordinate of the specified rectangle.
Syntax: CGFloat CGRectGetMidX(CGRect rect);
CGRectGetMidY: it takes CGRect reference and returns the center value of the y-coordinate of the specified rectangle.
Syntax: CGFloat CGRectGetMidY(CGRect rect);
CGRectGetMaxX: it takes CGRect reference and returns the height of x-coordinate of the specified rectangle.
Syntax: CGFloat CGRectGetMaxX(CGRect rect);
CGRectGetMaxY: it takes CGRect reference and returns the height of y-coordinate of the specified rectangle.
Syntax: CGFloat CGRectGetMaxY(CGRect rect);
CGGeometry provides many methods to get the point, according to the specified coordinates, some are:
CGPointMake: it takes two CGFloat reference and returns the point.
Syntax: CGPoint CGPointMake (CGFloat x, CGFloat y);
CGRectMake: it takes two coordinates of type CGFloat and size (width and height) of type CGFloat, it will return a rectangle using the specified coordinate.
Syntax: CGRect CGRectMake (CGFloat x, CGFloat y, CGFloat width, CGFloat height);
Anonymous User
23-Apr-2016